#ifndef GAME_H
#define GAME_H

#include "Singleton.h"

#include <QDebug>
#include <QList>

enum REQUEST_TYPE
{
  None, Help, Print
};

class Request
{
public:
    Request(REQUEST_TYPE k):_kind(k){}
    virtual ~Request(){}
    REQUEST_TYPE GetKind(){ return _kind; }
private:
    REQUEST_TYPE _kind;
};

class HelpRequest: public Request
{
public:
    HelpRequest(REQUEST_TYPE k)
        :Request(k),_kind(k)
    {}
    virtual ~HelpRequest(){}
private:
    REQUEST_TYPE _kind;
};

class HelpHandler {
  public:
    HelpHandler(HelpHandler* h)
        :_successor(h)
    {

    }
    virtual ~HelpHandler(){}
    virtual void HandleHelp(HelpRequest* theRequest)
    {
        qInfo()<<"HelpHandler" << __FUNCTION__ << theRequest->GetKind();
        if(_successor != 0)
            _successor->HandleHelp(theRequest);
    }
    virtual void HandleRequest(Request* theRequest)
    {
        switch (theRequest->GetKind()) {
        case Help:
            HandleHelp((HelpRequest*)theRequest);
            break;
        default:
            break;
        }
    }
private:
    HelpHandler* _successor;
};

class TApplication: public HelpHandler {
  public:
    TApplication()
        :HelpHandler(0)
    {
        _parent = 0;
    }
    virtual ~TApplication(){}
    virtual void HandleHelp(HelpRequest* theRequest)
    {
        qInfo()<<"TApplication" << __FUNCTION__;
        if(_parent != 0)
            _parent->HandleHelp(theRequest);
    }
private:
    TApplication* _parent;
};

class TWidget: public HelpHandler {
  public:
    TWidget(TWidget* parent)
        :HelpHandler(parent)
    {
        _parent = parent;
    }
    virtual ~TWidget(){}
    virtual void HandleHelp(HelpRequest* theRequest)
    {
        qInfo()<<"TWidget" << __FUNCTION__;
        if(_parent != 0)
            _parent->HandleHelp(theRequest);
    }
private:
    TWidget* _parent;
};

class TButton: public TWidget {
  public:
    TButton(TButton* parent)
        :TWidget(parent)
    {
        _parent = parent;
    }
    virtual ~TButton(){}
    virtual void HandleHelp(HelpRequest* theRequest)
    {
        qInfo()<<"TButton" << __FUNCTION__;
        if(_parent != 0)
            _parent->HandleHelp(theRequest);
    }
private:
    TButton* _parent;
};

#endif // GAME_H
